﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ABCComputer.BLL;
using DTO;

namespace ABCComputer
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        private SanPhamBLL spBLL;
        protected void Page_Load(object sender, EventArgs e)
        {
            loadSanPhamMoi();
            loadSanPhamHot();
        }

        public void loadSanPhamMoi()
        {
            spBLL = new SanPhamBLL();
            List<SanPhamDTO> lst = new List<SanPhamDTO>();
            lst = spBLL.getListSanPhamMoi();
            DTLSanPhamMoi.DataSource = lst;
            DTLSanPhamMoi.DataBind();

        }

        public void loadSanPhamHot()
        {
            spBLL = new SanPhamBLL();
            List<SanPhamFullDTO> lst = new List<SanPhamFullDTO>();
            lst = spBLL.getListSanPhamHot();
            DTLSanPhamHot.DataSource = lst;
            DTLSanPhamHot.DataBind();

            loadHinhLenDataList(lst, DTLSanPhamHot);
        }

        // load hinh len datalist
        public void loadHinhLenDataList(List<SanPhamFullDTO> lst, DataList dtl)
        {
            for (int i = 0; i < lst.Count; i++)
            {
                string tenHinh = lst[i].LstHinhAnh[0].TenHinhAnh;
                Image img = (Image)dtl.Items[i].FindControl("imgHinhSP");
                img.ImageUrl = tenHinh;
            }
        }

       
    }
}